package py.edu.ucom.c417.cadira.panel;

import py.edu.ucom.c417.cadira.tablero.Tablero;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.view.View;

public class PanelFichaView extends View {
	public Tablero getBottomPanel() {
		return bottomPanel;
	}

	public void setBottomPanel(Tablero bottomPanel) {
		this.bottomPanel = bottomPanel;
	}

	private Context context;
	private Paint pintarTablero;
	private Tablero bottomPanel;


	public PanelFichaView(Context context) {
		super(context);
		this.context = context;
		this.bottomPanel = new Tablero(2, 6, this.context);
		setBackgroundColor(Color.BLACK);
		pintarTablero = new Paint();
	}

	@Override
	public void draw(Canvas canvas) {
		super.draw(canvas);
		if (bottomPanel == null)
			bottomPanel = new Tablero(2, 6, this.context);
		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < 6; j++) {
				pintarTablero.setColor(Color.BLACK);
				Rect r = new Rect();
				r = rectfToRect(bottomPanel.getTablero()[i][j].getRecCasilla());
				canvas.drawRect(bottomPanel.getTablero()[i][j].getRecCasilla(),
						pintarTablero);
				if (bottomPanel.getTablero()[i][j].getListFichasPanel().size() > 0) {
					bottomPanel.getTablero()[i][j].getListFichasPanel().get(0)
							.getImagen().setBounds(r);
					bottomPanel.getTablero()[i][j].getListFichasPanel().get(0)
							.getImagen().draw(canvas);
				}

			}
		}
		invalidate();
	}

	private Rect rectfToRect(RectF rf) {
		Rect r = new Rect();
		r.left = (int) rf.left;
		r.top = (int) rf.top;
		r.right = (int) rf.right;
		r.bottom = (int) rf.bottom;
		return r;
	}
}
